package com.lsk.staff;

import com.jfinal.aop.Before;
import com.jfinal.aop.Duang;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.lsk.util.ReturnData;

import java.util.Map;

/**
 * Created by Administrator on 2018-11-20.
 */
public class StaffController extends Controller {
    static StaffServices staffServices=new StaffServices();
    static StaffServices txStaffServices= Duang.duang(new StaffServices());
    /**
     * 员工列表
     */
    public void staffList(){
        renderJsp("staffList.jsp");
    }
    public void staffListData(){
        int page=getParaToInt("page");
        int size=getParaToInt("limit");
        Map map=staffServices.staffListService(page,size);
        setAttr("staffList",map);
        renderJson(map);
    }
    /**
     * 去员工详情页面
     * goStaffInfo
     */
    public void goStaffInfo(){
        String id=getPara("id");
        Record record=staffServices.getStaffInfo(id);
        setAttr("staffInfo",record);
        renderJsp("staffInfo.jsp");
    }

    /**
     * 保存员工信息
     */
    @Before(Tx.class)
    public void saveStaffInfo(){
        Map<String,String[]> map=getParaMap();
        ReturnData returnData=staffServices.saveStaffInfoServce(map);
        renderJson(returnData);
    }


}
